package com.example.juccode.juc01threadpool.demo02;

import com.example.juccode.juc01threadpool.demo01.CustomThreadFactory;

import java.util.concurrent.*;

/**
 * @author: zhongkui 1365693530@qq.com
 * @Date: 2025/10/22
 */
public class Demo02 {
    /**
     * 创建线程池 返回值
     * submit 有返回值
     * execute 没有返回值
     */
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建线程池
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, 1, 0L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(),
                new CustomThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        // 提交任务
        TaskDemo taskDemo = new TaskDemo(10);
        Future<Integer> submit = threadPool.submit(taskDemo);
        System.out.println("等于=" + submit.get());
        // 关闭线程池
        threadPool.shutdown();
    }

}

class TaskDemo implements Callable<Integer> {
    private Integer i;

    public TaskDemo(Integer i) {
        this.i = i;
    }

    @Override
    public Integer call() throws Exception {
        return i + 3;
    }
}
